// Created by WXX on 2021/9/16 9:41
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

class Solution {
public:
    vector<string> findWords(vector<string> &words) {
        string line[3] = {
                "qwertyuiop",
                "asdfghjkl",
                "zxcvbnm"
        };
        unordered_map<char, int> hash;
        for (int i = 0; i < 3; i++)
            for (auto &c : line[i])
                hash[c] = i;

        vector<string> res;
        for (auto &word : words) {
            unordered_set<int> S;
            for (auto c : word) S.insert(hash[tolower(c)]);
            if (S.size() == 1) res.push_back(word);
        }
        return res;
    }
};

void OutputBasicArray1D(vector<string> nums) {
    cout << "[";
    for (int i = 0; i < nums.size(); i++) {
        cout << nums[i];
        if (i != nums.size() - 1) cout << ", ";
    }
    cout << "]" << endl;
}

int main() {

    vector<string> words = {"Hello", "Alaska", "Dad", "Peace"};
    OutputBasicArray1D(Solution().findWords(words));

    return 0;
}
